(function(global) {
    var weather = weather || {};
    var GOOGLE_WEAHER_API = 'http://www.google.com/ig/api?hl=zh-cn&weather=,,,';

    weather.xmlParser = function(xml) {
        var obj = {};
        var rawConditions = $(xml).find('weather').find('current_conditions');
        obj.condition = rawConditions.find('condition').attr('data');
        obj.temp_c = rawConditions.find('temp_c').attr('data');
        obj.humidity = rawConditions.find('humidity').attr('data');
        obj.icon = rawConditions.find('icon').attr('data');
        obj.wind_condition = rawConditions.find('wind_condition').attr('data');

        return obj;
      };                               

    weather.getCurrentConditions = function(latitude, longitude) {
      var latStr = latitude.toString().replace('.', '').substr(0, 8);
      var lngStr = longitude.toString().replace('.', '').substr(0, 9);
      var url = GOOGLE_WEAHER_API + latStr + ',' + lngStr;
      $.ajax({
          type: "GET",
          url: url,
          dataType: "xml",
          success: weather.xmlParser
      });
    };

    global.weather = weather;
})(window);
